package com.ctcemti.mdm.project.sys.controller;


import com.ctcemti.mdm.common.result.Result;
import com.ctcemti.mdm.common.result.ResultEnum;
import com.ctcemti.mdm.project.sys.entity.LoginLog;
import com.ctcemti.mdm.project.sys.service.ILoginLogService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登录日志Controller
 * 
 * @author 
 * @date Tue Nov 12 14:30:37 CST 2019
 */
@RestController
@Api(value = "LoginController", description = "登录控制器类")
@RequestMapping("/system/loginlog")
public class LoginLogController
{

    @Autowired
    private ILoginLogService loginLogService;

    /**
     * 查询登录日志对象
     */
    @ApiOperation(value = "查询登录日志对象")
    @PostMapping("/query")
    @ApiImplicitParam(name="entity",value = "登录日志实体类")
    public Result<LoginLog> query(HttpServletRequest request, HttpServletResponse response ,Long id)
    {
        LoginLog loginLog = loginLogService.selectLoginLogById(id);
        return new Result<LoginLog>(ResultEnum.SUCCESS,loginLog);
    }

    /**
     * 查询登录日志列表
     */
    @ApiOperation(value = "查询登录日志列表")
    @PostMapping("/list")
    @ApiImplicitParam(name="entity",value = "登录日志实体类")
    public Result<PageInfo<LoginLog>> queryList(HttpServletRequest request, HttpServletResponse response ,LoginLog loginLog)
    {
        PageInfo<LoginLog> pageInfo = loginLogService.selectLoginLogList(loginLog);
        return new Result<PageInfo<LoginLog>>(ResultEnum.SUCCESS,pageInfo);
    }



    /**
     * 新增保存登录日志
     */
    @ApiOperation(value = "保存登录日志数据")
    @PostMapping("/add")
    @ApiImplicitParams({@ApiImplicitParam(name="entity",value = "登录日志数据实体类")})
    public Result<LoginLog> insertLoginLog(HttpServletRequest request, HttpServletResponse response ,LoginLog loginLog)
    {
         loginLogService.insertLoginLog(loginLog);
         return new Result<LoginLog>(ResultEnum.SUCCESS,null);
    }

    /**
     * 修改登录日志
     */
    @ApiOperation(value = "更新登录日志数据")
    @PostMapping("/update")
    @ApiImplicitParam(name="entity",value = "登录日志数据实体类")
    public Result<LoginLog> updateLoginLog(HttpServletRequest request, HttpServletResponse response,  LoginLog loginLog)
    {
        loginLogService.updateLoginLog(loginLog);
        return new Result<LoginLog>(ResultEnum.SUCCESS,null);
    }


    /**
     * 删除登录日志
     */
    @ApiOperation(value = "删除登录日志")
    @PostMapping("delete")
    @ApiImplicitParams({@ApiImplicitParam(name="ids",value = "主键ids串")})
    public Result<LoginLog> remove(HttpServletRequest request, HttpServletResponse response ,String ids)
    {
        loginLogService.deleteLoginLogByIds(ids);
        return new Result<LoginLog>(ResultEnum.SUCCESS,null);
    }
}
